package com.qst.rongxiaoserver.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qst.rongxiaoserver.common.Result;
import com.qst.rongxiaoserver.model.AddressModel;
import com.qst.rongxiaoserver.model.QuestionModel;
import com.qst.rongxiaoserver.model.dto.QuestionDto;
import com.qst.rongxiaoserver.service.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/question")
@Tag(name = "问题管理", description = "问题管理")
public class QuestionController {
    @Autowired
    IQuestionService questionService;

    @PostMapping("/add")
    @Operation(summary = "预约问题", description = "添加预约问题(服务层实现)")
    public Result add(@Valid @RequestBody QuestionDto QuestionDto) {
      boolean res =   questionService.addQuestion(QuestionDto);
      return res ? Result.success("添加成功"):Result.fail("添加失败");
    }

    // 修改问题
    @PostMapping("/update")
    @Operation(summary = "修改问题", description = "修改问题(服务层实现)")
    public Result update(@Valid @RequestBody QuestionDto QuestionDto) {
        boolean res =   questionService.updateQuestion(QuestionDto);
        return res? Result.success("修改成功"):Result.fail("修改失败");
    }

    // 根据id查询某一条数据
    @GetMapping("/getById")
    @Operation(summary = "查询问题", description = "查询问题(服务层实现)")
    public Result<QuestionModel> getById(@Valid @RequestParam Integer id) {
        QuestionModel QuestionModel = questionService.getById(id);
        return Result.success(QuestionModel);
    }

    // 分页查询所有问题
    @GetMapping("/list")
    @Operation(summary = "查询所有问题", description = "查询所有问题(服务层实现)")
    public Result list(@RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {

       Page<QuestionModel> data =  questionService.getQuestionByPage(pageNum,pageSize);
        return Result.success(data);
    }


}
